package com.hzvdvmc.autosale.setting.adapter;

import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hzvdvmc.autosale.R;
import com.hzvdvmc.autosale.common.OnItemClickListener;
import com.hzvdvmc.autosale.setting.bean.TuneSetBean;

import org.w3c.dom.Text;

import java.util.List;

/**
 * Created by william on 2018/1/18.
 */

public class CabinetRowAdapter extends RecyclerView.Adapter<CabinetRowAdapter.CabinetRowHolder> {

    private List<TuneSetBean.Cabinet.shopRow> dataList;
    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public CabinetRowAdapter(List<TuneSetBean.Cabinet.shopRow> dataList) {
        this.dataList = dataList;
    }

    @Override
    public CabinetRowHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_cabinet_row, parent, false);
        return new CabinetRowHolder(itemView);
    }

    @Override
    public void onBindViewHolder(CabinetRowHolder holder, final int position) {

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.onClick(v, position);
                }
            }
        });
        holder.tvLabel.setText("货盘 " + (position + 1));
        String tuneCount = dataList.get(position).getTuneCount();
        if (TextUtils.isEmpty(tuneCount)) {
            holder.tvCount.setText("0");
        } else {
            holder.tvCount.setText(tuneCount);
        }

    }

    @Override
    public int getItemCount() {
        return dataList == null ? 0 : dataList.size();
    }

    public class CabinetRowHolder extends RecyclerView.ViewHolder {
        private TextView tvLabel;
        private TextView tvCount;

        public CabinetRowHolder(View itemView) {
            super(itemView);
            tvLabel = (TextView) itemView.findViewById(R.id.tv_label);
            tvCount = (TextView) itemView.findViewById(R.id.tv_count);
        }
    }

}
